package main

import "fmt"

func main() {
	a, b := 3, 4
	fmt.Println("start swap ", a, b)

	fmt.Println()

	swap(a, b)
	fmt.Println("start swap ", a, b)

	swapByPointer(&a, &b)
	fmt.Println("start swap ", a, b)

}

// 尝试交换ab的值，发现是失败的，没有换成功
func swap(a, b int) {
	temp := b
	b = a
	a = temp
}

// 使用指针交换成功
func swapByPointer(a, b *int) {
	temp := *b
	*b = *a
	*a = temp
}
